package com.leoandroid.tool.toolsbox.largeread.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.leoandroid.tool.toolsbox.largeread.R;
import com.leoandroid.tool.toolsbox.largeread.utils.FlashlightUtils;

public class MultiFunctionActivity extends BaseActivity{

    private LinearLayout layoutSos;
    private LinearLayout layoutFlashLamp;
    private LinearLayout layoutAlarmLamp;
    private LinearLayout layoutScreenLamp;
    private LinearLayout layoutIllumination;
    private LinearLayout layoutCautionLamp;
    private ImageView imgSos;
    private TextView tvSos;

    private boolean isSosOpen = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_classify);
        initView();
    }

    private void initView(){
        layoutSos = findViewById(R.id.sos_layout);
        imgSos = findViewById(R.id.sos_img);
        tvSos = findViewById(R.id.sos_tv);
        layoutFlashLamp = findViewById(R.id.flash_lamp_layout);
        layoutAlarmLamp = findViewById(R.id.alarm_lamp_layout);
        layoutScreenLamp = findViewById(R.id.screen_lamp_layout);
        layoutIllumination = findViewById(R.id.illumination_layout);
        layoutCautionLamp = findViewById(R.id.caution_lamp_layout);

        layoutSos.setOnClickListener(view -> {
            if(!isSosOpen){
                layoutSos.setBackgroundResource(R.drawable.bg_black_10dp);
                imgSos.setImageResource(R.mipmap.ic_multifunction_sos_on);
                tvSos.setTextColor(getResources().getColor(R.color.color_f3f3f3));
                FlashlightUtils.sos(5);
                isSosOpen = true;
            }else{
                layoutSos.setBackgroundResource(R.drawable.bg_white_10dp);
                imgSos.setImageResource(R.mipmap.ic_multifunction_sos_default);
                tvSos.setTextColor(getResources().getColor(R.color.color_333333));
                FlashlightUtils.offSos();
                isSosOpen = false;
            }
        });

        layoutFlashLamp.setOnClickListener(view -> {
            Intent intent = new Intent(this, FlashLightActivity.class);
            startActivity(intent);
        });

        layoutAlarmLamp.setOnClickListener(view -> {
            Intent intent = new Intent(this, AlarmLightActivity.class);
            startActivity(intent);
        });

        layoutScreenLamp.setOnClickListener(view -> {
            Intent intent = new Intent(this, ScreenLightActivity.class);
            startActivity(intent);
        });

        layoutIllumination.setOnClickListener(view -> {
            Intent intent = new Intent(this, MultiLightActivity.class);
            startActivity(intent);
        });

        layoutCautionLamp.setOnClickListener(view -> {
            Intent intent = new Intent(this, WarningLightActivity.class);
            startActivity(intent);
        });
    }
}
